package com.ideal.manage.esms.repository.alarm;

import com.ideal.manage.esms.bean.alarm.Alarm;
import com.ideal.manage.esms.bean.project.AlarmInfo;
import com.ideal.manage.esms.repository.framework.BaseRepository;
import org.springframework.data.jpa.repository.Query;

import java.util.Date;
import java.util.List;

public interface AlarmRepository extends BaseRepository<Alarm,String> {

    @Query("select a.state from Alarm a ")
    List<Alarm> findAlarmByState();

    @Query("select a from Alarm a where a.equipmentId=?1 and a.state !=3 ")
    List<Alarm> findAlarmById(String id);

    /*
     * 根据项目id查找到所有未处理和已确认的报警的总数
     * @param project_id
     * @return
     */
    @Query("select count(a.id) from Alarm a where a.equipmentId.id=?1 and a.isValid=1 and a.state<3")
    Long findAlarmCountById(String project_id);

    @Query("select a from Alarm a where a.isValid=1")
    List<Alarm> findAlarmByValid();

    @Query("select a from Alarm a where a.alarmLev<5 and a.isValid = 1 ")
    List<Alarm> findAlarmLev();

  /*  @Query("select a from Alarm a where a.createTime like %?1 and a.isValid=1")
    List<Alarm> findByAlarmToday(Date today);*/


    /**
     * @查找sys_alarm_info表中数据
     * @param alarmLev 告警等级
     * @param alarmCanName ES中告警字段code
     * @return
     */

    @Query("select a from AlarmInfo a where a.alarmLev=?1 and a.alarmCanName=?2 and a.isValid =1")
    List<AlarmInfo> findAlarmInfoByLevandEsname(Integer alarmLev, String alarmCanName);

    @Query("select count (a.alarmLev) from Alarm a where a.isValid=1 and a.alarmLev=?1 and a.createTime>?2 and a.createTime<?3")
    Double findByAlarmLev( String j, Date startTime, Date endTime );

    @Query("select a from Alarm a where a.isValid=1 and a.createTime>?1 and a.createTime<?2 and a.alarmLev=?3")
    List<Alarm> findByAlarmLevData(Date beginDayOfYear, Date endDayOfYear, String s);
}
